import testlink
import time

test_url= "http://192.168.0.201/testlink/lib/api/xmlrpc/v1/xmlrpc.php"
test_key = "a695a58b5cde364a3a669bac4302054a"
tlc = testlink.TestlinkAPIClient(test_url, test_key)

suite_case_id = tlc.getTestCasesForTestSuite(testsuiteid='298464', deep=True, details='only_id') #改这里的testsuiteid(支持多个子目录)

suite_case_id_2 = tlc.getTestCasesForTestSuite(testsuiteid='298464', deep=True, details='full') #改这里的testsuiteid(支持多个子目录)
for k in suite_case_id_2:
    print(k['preconditions'])

dic = []
a = 0
for j in suite_case_id:
    list_dic = {}
    one_piece = tlc.getTestCase(j)
    data = one_piece[0]['summary']
    data_2 = one_piece[0]['preconditions']
    data_3 = one_piece[0]['steps']

    all_actions = []
    for i in one_piece[0]['steps']:
        i['actions'] = i['actions'].replace('old','new')            #批量化修改测试步骤动作内容
        all_actions.append(i)

    data = data.replace('old','new')                                #批量化修改摘要的内容

    data_2 = data_2.replace("/testlink/third_party/kcfinder/upload/images/WTM2102.jpg","new")                            #批量化修改前提的内容

    list_dic['ID'] = j
    list_dic['summary'] = data
    list_dic['preconditions'] = data_2
    list_dic['steps'] = all_actions

    dic.append(list_dic)

for i in dic:
    tlc.updateTestCase(testcaseid=i['ID'], summary = i['summary'],preconditions = i['preconditions'], steps=i['steps'])
    print(time.asctime())

print('_____________finish______________')

